package com.library.controller;

import com.library.bean.User;
import com.library.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RequestMapping("user")
@Controller
public class UserController {

    @Resource
    private UserService us;

    @RequestMapping("/login")
    public String login(User user, Model model,HttpSession session) {
        Map<String, Object> map = us.userLogin(user);
        if (map.containsKey("loginUser")) {
            session.setAttribute("loginUser", map.get("loginUser"));
            return "redirect:/books";
        }
        model.addAttribute("msg", map.get("msg"));
          return "forward:/login.jsp";
    }
}
